<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('团队名称')" prop="deptId">
            <el-input v-model="form.deptId" :placeholder="$t('团队名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('团队负责人')" prop="deptPrincipal">
            <el-input v-model="form.deptPrincipal" :placeholder="$t('团队负责人')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('联系方式')" prop="contactWay">
            <el-input v-model="form.contactWay" :placeholder="$t('联系方式')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="mediation:team" />
    </div>
  </div>
</template>

<script>
    import { saveMediationTeam, getMediationTeam } from '@/api/deal/mediation/mediationTeam/mediationTeam'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  deptId: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ]
                }
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getMediationTeam(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                      this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            initData(data) {
              this.loading = true
              this.reset()
              this.form.mediationId = data
              this.loading = false
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    mediationId: this.$route.query.id,
                    deptId: undefined,
                    deptPrincipal: undefined,
                    contactWay: undefined,
                    remark: undefined,
                    sort: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                if (this.$parent.$parent.teamFormOpen !== undefined) {
                  this.$parent.$parent.teamFormOpen = false
                } else {
                  this.$parent.$parent.reset()
                }
            },
            // 关闭form页面
            closeForm(form) {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                if (this.$parent.$parent.processingDataEcho !== undefined) {
                  const data = {
                    id: form.id,
                    deptName: form.deptId
                  }
                  this.$parent.$parent.processingDataEcho(data, 'mediationTeamForm')
                }
                if (this.$parent.$parent.teamFormOpen !== undefined) {
                  this.$parent.$parent.teamFormOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveMediationTeam(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm(response.data)
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
